import { Moment } from "moment";
import { SagaIterator } from "redux-saga";
import { call, put, takeEvery } from "redux-saga/effects";
import { BudgetItem } from "../../interface/budgetData";
import { ActionProps } from "../type";
import { SelectBudgetListDataAction } from "./budget-list-action";
import { FetchBudgetListDataApi } from "./budget-list-api";
import { BudgetListActionEnum } from "./budget-list-type";

function* GetBudgetListDataSaga({ type, payload }: ActionProps<string, Moment[]>): SagaIterator
{
    let fetchBudgetListData: BudgetItem[] = yield call(FetchBudgetListDataApi, payload);
    if (fetchBudgetListData)
    {
        let action: ActionProps<BudgetListActionEnum, BudgetItem[]>;
        action = SelectBudgetListDataAction(fetchBudgetListData);
        yield put(action);
    }
}
export function* SelectBudgetListData()
{
    yield takeEvery("GetBudgetListData", GetBudgetListDataSaga);
}
